package org.springcloud.wisdom.spring_01_canteen.indentdetail;

import org.springcloud.wisdom.spring_01_canteen.indent.Indent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/indentdetail")
public class IndentDetailController {
    @Autowired
    private IndentDetailService indentDetailService;
    //获取订单详情
    @GetMapping("/list")
    public List<IndentDetail> listAll() {
        return indentDetailService.listAll();
    }

    @PostMapping("/importFromCart")
    public void importFromCart(@RequestParam String indentdetailid) {
        indentDetailService.importFromCart(indentdetailid);
        System.out.println(indentdetailid);
    }

    @GetMapping("/listByIndentId/{indentdetailid}")
    public ResponseEntity<List<IndentDetail>> listByIndentid(@PathVariable String indentdetailid) {
        List<IndentDetail> indentDetails = indentDetailService.listByIndentId(indentdetailid);
        if (indentDetails != null && !indentDetails.isEmpty()) {
            return ResponseEntity.ok(indentDetails);
        } else {
            return ResponseEntity.notFound().build();
        }
    }


}
